package com.woniuxy.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.pojo.SysLogOpt;
import com.woniuxy.pojo.dto.SysLogOptDTO;
import com.woniuxy.service.SysLogOptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys_log_opt")
public class SysLogOptController {

    @Autowired
    SysLogOptService sysLogOptService;

    @PostMapping("/getLogList/{pageNum}/{pageSize}")
    public ResponseEntity<?> getLogList(@PathVariable Integer pageNum,
                                        @PathVariable Integer pageSize,
                                        @RequestBody(required = false) SysLogOptDTO logOptDTO){
        Page<SysLogOpt> sysLogOptPage = new Page<>(pageNum,pageSize);
        //添加综合查询条件
        LambdaQueryWrapper<SysLogOpt> wrapper = new LambdaQueryWrapper<>();
        if(logOptDTO != null && logOptDTO.getUname() != null && !logOptDTO.getUname().equals("")){
            wrapper.like(SysLogOpt::getUName,logOptDTO.getUname());
        }
        if(logOptDTO != null && logOptDTO.getStartTime() != null && logOptDTO.getEndTime() != null){
            wrapper.between(SysLogOpt::getOptTime,logOptDTO.getStartTime(),logOptDTO.getEndTime());
        }
        sysLogOptService.page(sysLogOptPage,wrapper);
        return ResponseEntity.ok(sysLogOptPage);
    }
    @PostMapping("/deleteLogs")
    public ResponseEntity<?> deleteLogs(@RequestBody List<Integer> ids){
        boolean b = sysLogOptService.removeBatchByIds(ids);
        return ResponseEntity.ok(b);
    }
}
